package com.tz.controller;

import com.tz.entity.ResearchTemplate;
import com.tz.service.ResearchTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Alex
 * @date 18/1/9
 */
@Controller
@RequestMapping("/temple")
public class TempController {

    private final ResearchTemplateService researchTemplateService;

    @Autowired
    public TempController(ResearchTemplateService researchTemplateService) {
        this.researchTemplateService = researchTemplateService;
    }

    @ResponseBody
    @RequestMapping("/mod")
    public ResearchTemplate modTemp(@RequestBody Long id) {
        System.out.println(id);
        return researchTemplateService.getResearchTemplate(id);
    }

    @ResponseBody
    @RequestMapping("/domod")
    public String doMod(@RequestBody ResearchTemplate researchTemplate) {
        if (researchTemplate != null) {

            if (researchTemplate.getTempid() == null || researchTemplate.getTempid() == 0) {
                researchTemplate.setStatus(1);
                researchTemplateService.addTemplate(researchTemplate);
            } else {
                researchTemplate.setStatus(1);
                researchTemplateService.alterTemplate(researchTemplate);
            }

            return "ok";
        } else {

            return "false";
        }

    }

}
